package com.my.fp.list;

import com.my.bean.User;
import com.my.utils.Utils;

import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author: marshal
 * @date: 2021-09-02 11:32 AM
 * <p>
 * list 转 map
 */
public class ToMapTest {
    public static void main(String[] args) {
        var list = Utils.getUsers();
        // 转化为 name-age map
        var nameAgeMap = list.stream().collect(Collectors.toMap(User::getName, User::getAge));
        System.out.println(nameAgeMap);

        // 转化为 id-user map
        var idUserMap = list.stream().collect(Collectors.toMap(User::getId, Function.identity()));
        System.out.println(idUserMap);
    }
}